<?php
/** ensure this file is being included by a parent file */
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

// include support libraries
//require_once( $mainframe->getPath( 'admin_html' ) );

// handle the task
$task = mosGetParam( $_REQUEST, 'task', '' );

switch ($task) {
	case 'clean':
		clean();
		break;
	default:
		showCleanForm();
		break;
}

/**
 * Polite hello event
 */
function clean() {
	global $database;
	// clean mgmediabot db table
	$query = "DELETE FROM #__mgmediabot_playerscache";
	$database->SetQuery($query);
	$result = $database->query();
	echo $result;
	mosCache::cleanCache( 'com_content' );
    mosRedirect( 'index2.php', 'Content caches cleaned' );
}

function showCleanForm() {
	echo "<h3>MgMediabot cache cleanup</h3>";
	echo "Clean up mgmediabot playerscache and content cache!";
	echo "<form><input type='submit' name='submit' value='Clean up' /><input type='hidden' name='task' value='clean' /><input type='hidden' name='option' value='com_mgmedia2' /></form>";
}
?>
